
layui.use('table', function() {
	var table = layui.table,form = layui.form; 
	layer.msg('数据加载中...', {
		icon: 16,
		shade: 0.3,
		success: function() {
			$.ajax({
				type:'post',
				dataType:'json',
				url:listSrc,
				success:function(data){
					var code=data.code;
    		        var msg=data.msg;
    		        var arr = []
					$.each(data, function(index,value) {
						arr.push(value);
					});
					table.render({
						elem: '#centet-cen',
						height: $(".center-tab").height(),
						id:'idTest',
						cols: [
							[ //标题栏
								{
									field: 'id',
									title: 'ID',
									sort: true,
									width: 80
								}, {
									field: 'bonus_tag',
									title: '奖金名称',
									width: 150
								}, {
									field: 'bonus_name',
									title: '奖金别名',
									sort: true,
									width: 150
								}, /*{
									field: 'status',
									title: '状态',
									templet: '#switchTpl', 
									unresize: true,
									width: 150
								},*/ {
									field: 'oper',
									title: '操作',
									toolbar: '#barDemo'
								}

							]
						],
						data: arr,
						limit: 30
				    });
					var pageHtml=data.page_html;
					$(".paging").html(pageHtml);
					layer.close(layer.index)
					
				}
			});
		}
		
		
	})
	
	//监听性别操作
	form.on('switch(sexDemo)', function(obj){
	   var status;
	   if(obj.elem.checked, obj.othis == true) {
			status = 1;
		} else {
			status = 0;
		}
	    $.ajax({
			type: 'post',
			dataType: 'json',
			url: changeSec,
			data: 'plugin=' + this.value + '&status=' + status,
			success: function(data) {
				var msg=data.msg;
				layer.alert(this.name + msg,{icon: 1},function(){
    				location.reload();
    			})
			}
		});
	});
	table.on('tool(table)', function(obj) {
		var data = obj.data;
		if(obj.event === 'edit') {
			var name=data.bonus_name;
			var id=data.id;
			var src=''+editSrc+'?name='+name+'&data-mid='+id+'';
			window.location.href=src; 
		}
	});
	
	
})






layui.use('layer', function() {
	var $ = layui.jquery,
		layer = layui.layer;
	var active = {
		add: function() {
			  layer.open({
			  type: 1,
			  title:"新增等级",
			  area: ['550px', '290px'], //宽高
			  maxmin: true,
			  resize:true,
			  content: addhtml,
			  btn: ['提交', '关闭'],
			  btn1: function(){
			  	var Adata=$("#fomr").serialize();
			    $.ajax({
			    	type:'post',
			    	dataType:'json',
			    	url:addSrc,
			    	data:Adata,
			    	success:function(data){
			    		var code=data.code;
			    		var msg=data.msg;
			    		if(code==1){
			    			layer.close(layer.index)
			    			layer.alert(msg,{icon: 1},function(){
			    				location.reload();
			    			})
			    		}else{
			    			layer.alert(msg,{icon: 5})
			    		}
			    	}
			    })
			  }
			});
		}
	}
	$('.right-center').on('click', '.right-btn', function() {
		var othis = $(this),method = othis.data('method');
		active[method] ? active[method].call(this, othis) : '';
	});
})








